window.onload = function(){
	// 学生端与教师端切换
	let backgrouund ;
	const login = new Vue({
		el:'#login',
		data:{
			validate : 'POUy',
			isStu : true
		},
		methods:{
			submitClick(){
				var name = document.getElementById("studentName").value;
				var examNumber = document.getElementById("candidateNumber").value;
				var chekCode = document.getElementById("validateCode1").value;
				var xhttp = new XMLHttpRequest();
				xhttp.onreadystatechange = function() {
					if (this.readyState == 4 && this.status == 200) {
				if("nameNull" == this.getResponseHeader("loginInformation"))
				{
					alert("请输入考生号");
				}
				else if("numberNull" == this.getResponseHeader("loginInformation"))
				{
					alert("请输入姓名");
				}
				else if("checkCodeNull" == this.getResponseHeader("loginInformation"))
				{
					alert("请输入验证码");
				}
				else if("checkCodeWrong" == this.getResponseHeader("loginInformation"))
				{
					alert("验证码错误");
				}
				else if("checkCodeOutOfDate" == this.getResponseHeader("loginInformation"))
				{
					alert("验证码过期请重新输入");
					document.getElementById("validateCode1").value = "";
					changeCheckCode();
				}
				else if("noSuchStudent" == this.getResponseHeader("loginInformation"))
				{
					alert("信息错误或您没被录取");
				}
				else if("congratulations" == this.getResponseHeader("loginInformation"))
				{
					document.getElementById("html").innerHTML = this.responseText;
				}


						changeCheckCode();
					}
				};
				xhttp.open("post", "/login/StudentLogin?StudentName="
					+ name + "&examStudentNumber=" + examNumber
					+ "&checkCode=" + chekCode, true);
				xhttp.send();
				console.log('submit');
			},
			submitClick1(){
				var payrollNumber = document.getElementById("teacherName").value;
				var password = document.getElementById("password").value;
				var chekCode = document.getElementById("validateCode2").value;
				var xhttp = new XMLHttpRequest();
				xhttp.onreadystatechange = function() {
					if (xhttp.readyState != 4)
					{
						return;
					}
					var loginInformation = this.getResponseHeader("loginInformation");
					//工资号空
					if ("payrollNumberNull" == loginInformation)
					{

					}
					//密码空
					else if("passwordNull" == loginInformation)
					{

					}
					//验证码空
					else if("checkCodeNull" == loginInformation)
					{

					}
					//验证码错误
					else if("checkCodeWrong" == loginInformation)
					{

					}
					//验证码过期
					else if("checkCodeOutOfDate" == this.getResponseHeader("loginInformation"))
					{
						alert("验证码过期请重新输入");
						document.getElementById("validateCode1").value = "";
						changeCheckCode();
					}
					//工资号或密码错误
					else if("InformationWrong" == loginInformation)
					{

					}
					else
					{

					}

					if (this.getResponseHeader("href") != null)
					{
						window.location.href = this.getResponseHeader("href");
					}
				};
				xhttp.open("post", "/login/TeacherLoginServlet?payrollNumber="
					+ payrollNumber + "&password=" + password
					+ "&checkCode=" + chekCode, true);
				xhttp.send();
			},
			isStudent(){
				this.isStu = !this.isStu;
				const bg2 = document.body.style.backgroundImage = "url(img/indexBg2.jpg)";
				const bg4 = document.body.style.backgroundImage = "url(img/indexBg4.jpg)";
				this.isStu ? bg2 : bg4;
			}
		}
	})
	//页面缩小到900px后的显示形式
	window.onresize = function(){
		const studentLogin = document.getElementById('studentLogin');
		const teacherLogin = document.getElementById('teacherLogin');
		if(document.documentElement.clientWidth <= 900){
			studentLogin.style.left = '50%';
			teacherLogin.style.left = '50%';
			studentLogin.style.transform = 'translateX(-50%)';
			teacherLogin.style.transform = 'translateX(-50%)';
		}else if(document.documentElement.clientWidth <= 1400 && document.documentElement.clientWidth >800){
			studentLogin.style.left = '55%';
			teacherLogin.style.right = '60%';
			studentLogin.style.transform = 'translateX(-50%)';
			teacherLogin.style.transform = 'translateX(-50%)';
		}else{
			studentLogin.style.left = '55%';
			teacherLogin.style.left = '40%';
			studentLogin.style.transform = 'translateX(0)';
			teacherLogin.style.transform = 'translateX(-100%)';
		}
	}
	// 学生端、教师端 页面更换背景图片
	const background1 = document.getElementById('background1');
	const background2 = document.getElementById('background2');
	let bgIndex = 2;
	background1.onclick = function(){
		if(bgIndex>1){
			bgIndex-- ;
		}else{
			bgIndex=3;
		}
		document.body.style.backgroundImage = "url(img/indexBg"+bgIndex+".jpg)";
	}
	background2.onclick = function(){
		if(bgIndex<3){
			bgIndex++ ;
		}else{
			bgIndex=1;
		}
		document.body.style.backgroundImage = "url(img/indexBg"+bgIndex+".jpg)";
	}
	var  timer=	setInterval(function(){
		bgIndex++;
		console.log(login.isStu);
		if(bgIndex>3){
			bgIndex=1;
		}
		document.body.style.backgroundImage = "url(img/indexBg"+bgIndex+".jpg)";
		if(!login.isStu){
			clearInterval(timer);
			document.body.style.backgroundImage = "url(img/indexBg4.jpg)";
		}
	},5000);
	// 学生端信息输入验证


	const studentName = document.getElementById('studentName');
	const candidateNumber = document.getElementById('candidateNumber');
	const validateCode = document.getElementById('validateCode');
	studentName.onblur = function(){
		let reg = /^[\u4E00-\u9FA5]{2,15}$/;
		let str = studentName.value;
		if (reg.test(str)){
			studentName.style.border = '1px solid green' ;
		}else{
			studentName.style.border = '1px solid red' ;
		}
	}
	candidateNumber.onblur = function(){
		let reg = /^[0-9]{14}$/;
		let str = candidateNumber.value;
		if (reg.test(str)){
			candidateNumber.style.border = '1px solid green' ;
		}else{
			candidateNumber.style.border = '1px solid red' ;
		}
	}
	// 教师端信息输入验证
	const teacherName = document.getElementById('teacherName');
	const password = document.getElementById('password');
	teacherName.onblur = function(){
		let reg = /^[0-9]{0,8}$/;
		let str = teacherName.value;
		if (reg.test(str)){
			teacherName.style.border = '1px solid green' ;
		}else{
			teacherName.style.border = '1px solid red' ;
		}
	}
	password.onblur = function(){
		let reg = /^[0-9]{0,8}$/;
		let str = password.value;
		if (reg.test(str)){
			password.style.border = '1px solid green' ;
		}else{
			password.style.border = '1px solid red' ;
		}
	}
	//教师端密码框小眼睛
	const eyeOpen = document.getElementsByClassName('eyeOpen')[0];
	const eyeClose = document.getElementsByClassName('eyeClose')[0];
	eyeClose.onclick =function(){
		password.type = 'text';
		eyeOpen.style.display = 'block';
		eyeClose.style.display = 'none';
	}
	eyeOpen.onclick =function(){
		password.type = 'password';
		eyeOpen.style.display = 'none';
		eyeClose.style.display = 'block';
	}
	function uploadPic() {

		alert(111)
		var form = document.getElementById('file'),
	        formData = new FormData(form);
		$.ajax({
	        url:"/ExcelInServlet",
	        type:"post",
	        data:formData,
	        processData:false,
	        contentType:false,
	        success:function(res){
	            if(res){
	                alert("上传成功！");
	            }
	            console.log(res);
	            $("#pic").val("");
	            $(".showUrl").html(res);
	            $(".showPic").attr("src",res);
	        },
	        error:function(err){
	            alert("网络连接失败,稍后重试",err);
	        }

	    })
	}

	const changeValidate = document.getElementById('changeValidate');

	const changeValidate2 = document.getElementById('changeValidate2');
	const checkCodeImg = document.getElementById('checkCode');
	const checkCodeImg2 = document.getElementById('checkCode2');
	const checkCodeDiv = document.getElementById('checkCodeDiv');
	const checkCodeDiv2 = document.getElementById('checkCodeDiv2');
	//验证码图片更换
	function changeCheckCode(){
		checkCodeImg.src = "/checkCode?" + new Date().getTime();
		checkCodeImg2.src = "/checkCode?" + new Date().getTime();
	}
	changeValidate.onclick = changeCheckCode;
	checkCodeDiv.onclick = changeCheckCode;
	changeValidate2.onclick = changeCheckCode;
	checkCodeDiv2.onclick = changeCheckCode;
	changeCheckCode();
}
